<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.cloudvender"/></h1>	
</div>
<form:form modelAttribute="venderEntityModel" role="form" cssClass="form-horizontal">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<form:input path="userid" type="hidden"/>
	<form:input path="venderid" type="hidden"/>	
	<div class="form-group">
		<form:label path="venderName" cssClass="col-sm-2 control-label "><spring:message code="configration.cloud.venderName"/></form:label>
		<div class="col-sm-4"> 
			<form:input path="venderName" cssClass="form-control edit-form"/>
		</div>				
	</div>
	
	<div class="form-group">
		<form:label path="typeSeq" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.supported.list"/></form:label>
		<div class="col-sm-2">			
			<form:select path="typeSeq" items="${venderTypeList }" itemLabel="typeName" itemValue="typeSeq" cssClass="form-control"></form:select>			
		</div>
	</div>
		
	<div class="form-group">
		<form:label path="venderDesc" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.venderDesc"/></form:label>
		<div class="col-sm-10"><form:textarea path="venderDesc"  cssClass="form-control edit-form" /></div>
	</div>
	
	<div class="col-sm-12 text-right">
		<button class="btn btn-default btn_link" data-link="./lists" type="button"><spring:message code="button.list"/></button>
		<c:if test="${fn:contains(buttons , Authorities.UPDATE)}">
		<button class="btn btn-primary updateBtn" type="button"><spring:message code="button.edit"/></button>
		<button class="btn btn-success updateSubmitBtn" type="button"><spring:message code="button.edit"/></button>		
		</c:if>
		<c:if test="${fn:contains(buttons , Authorities.REMOVE)}">
		<button class="btn btn-primary removeBtn" type="button"><spring:message code="button.delete"/></button>
		</c:if>
	</div>
</form:form>

<script type="text/javascript"><!-- 
$(document).ready(function(){
	$(".form-horizontal").find(":input").attr("disabled","true");
	$(".form-horizontal").find(".btn").removeAttr("disabled");
	$(".updateSubmitBtn").hide();
});
$(document).on("click", ".updateBtn", function() {
	$(".edit-form").removeAttr("disabled");
	$(".updateSubmitBtn").show();
	$(this).hide();
}).on("click", ".updateSubmitBtn", function(){
	bootbox.confirm("<spring:message code='common.update.confirm'/>", function(result) {
		Notification.show("Confirm result: "+result);
		if ( result ) {
			Loading.show();
			$(".form-horizontal").find(":input").removeAttr("disabled");
			$.post("./edit", $("#venderEntityModel").serialize(), function(res) {
				
			}).fail(function() {
				bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
			}).done(function(res) {
				if ( res ) {
					bootbox.alert("<spring:message code='common.update.ok'/>", function() {
						Loading.link("./lists");							
					});
				} else {
					bootbox.alert("<spring:message code='common.update.fail'/>");
				}
			}).always(function() {
				Loading.hide();
			});
		}
	});
}).on("click", ".removeBtn", function() {
	bootbox.confirm("<spring:message code='common.remove.confirm'/>", function(result) {
		if ( result ) {
			Loading.show();
			$(".form-horizontal").find(":input").removeAttr("disabled");
			$.post("./remove", $("#venderEntityModel").serialize(), function(res) {
				
			}).fail(function() {
				bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
			}).done(function(res) {
				if ( res ) {
					bootbox.alert("<spring:message code='common.remove.ok'/>", function() {
						Loading.link("./lists");							
					});
				} else {
					bootbox.alert("<spring:message code='common.remove.fail'/>");
				}
			}).always(function() {
				Loading.hide();
			});
		}
	});
});
//--></script>